<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>组织机构</title>

		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="/static/manage/common/bootstrap/js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		
		<script type="text/javascript">
			
			//添加方法
			function add() {
				$("#myModal").modal("show")
			}
			
			//转换日期格式(时间戳转换为datetime格式)
			function changeDateFormat(cellval) {
				var dateVal = cellval + "";
				if(cellval != null) {
					var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
					var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
					var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

					var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
					var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
					var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

					return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
				}
			}



			$(function() {

				//				alert("json");

				//1.初始化Table

				var oTable = new TableInit();

				oTable.Init();

				var message = document.getElementById("message").value;

				if(message != null && message != "") {

					alert(message);

				}

			});

			var TableInit = function() {
				var oTableInit = new Object();
				//初始化Table
				oTableInit.Init = function() {

					$('#t').bootstrapTable({

						method: 'get',

						contentType: "application/x-www-form-urlencoded",

						url: "/sys/findDepts", //请求后台的URL（*）

						striped: true, //是否显示行间隔色

						locale: 'zh-CN', //中文支持

						pagination: true, //是否开启分页（*）

						pageNumber: 1, //初始化加载第一页，默认第一页

						pageSize: 2, //每页的记录行数（*）

						pageList: [2, 5, 10], //可供选择的每页的行数（*）

						sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）

						//showRefresh: true, //刷新按钮
						

						queryParams: oTableInit.queryParams, //传递参数（*）

						strictSearch: true,

						//showColumns: true, //是否显示所有的列

						minimumCountColumns: 2, //最少允许的列数

						clickToSelect: true, //是否启用点击选中行

						columns: [{
							title: '<input type="checkbox" id="all" onclick="checkAll()"/>',
							align: 'center',
							width:'40',
							formatter: function (value, row, index) {
							    return '<input name="che" type="checkbox" value="'+row.dept_id+'"/>'
							}
						},{
								title: '',
								align: 'center',
								width:'40',
								formatter: function (value, row, index) {
								    //获取每页显示的数量
								    var pageSize=$('#t').bootstrapTable('getOptions').pageSize;  
								    //获取当前是第几页  
								    var pageNumber=$('#t').bootstrapTable('getOptions').pageNumber;
								    //返回序号，注意index是从0开始的，所以要加上1
								    return pageSize * (pageNumber - 1) + index + 1;
								}
							},{
								field: 'dept_name',
								title: '机构名称',
								align: 'center'
							},{
								field: 'dept_code',
								title: '机构代码',
								align: 'center'
							},
							{
								field: 'manager',
								title: '主要负责人',
								align: 'center'
							}, {
								field: 'phone',
								title: '部门电话',
								align: 'center'
							}, {
								field: 'fax',
								title: '传真',
								align: 'center'
							}, {
								field: 'is_auto_expand',
								title: '自动展开',
								align: 'center',
								formatter: function(v, r, i) {
									switch(Number(v)) {
										case 1:
											return "是";
											break;
										case 2:
											return "否";
											break;
									}
								}
							}, {
								field: 'sort_no',
								title: '排序号',
								align: 'center'
							}, {
								field: 'icon_name',
								title: '节点图标',
								align: 'center'
							}, {
								field: 'remark',
								title: '备注',
								align: 'center'
							}]
					});

				};

				//得到查询的参数

				oTableInit.queryParams = function(params) {

					var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的

						limit: params.limit, //页面大小

						offset: params.offset, //偏移量
						pageSize:params.limit,

						dept_name: $("#dept_name").val()

						/* title: $("#PROTOCOL_NAME").val(),

						startTime: $("#startTime").val(),

						endTime: $("#endTime").val(),

						brand: $("#PROTOCOL_STATUS").val(),

						important: $("#PROTOCOL_TYPE").val() */
					};
					return temp;
				};
				return oTableInit;
			};
			
			
			function chaxun () {
				//alert($("#dept_name").val())
				$("#t").bootstrapTable('refresh');
			}
			
			function checkAll () {
				var allche = document.getElementById("all");
				var ches = document.getElementsByName("che");
				for (i = 0; i < ches.length; i++) {
					ches[i].checked = allche.checked;
				}
			}
			
			function findIds(ename) {
				arr = document.getElementsByName(ename);
				ids = [];
				for (k in arr) {
					if (arr[k].checked)
						ids.push(arr[k].value);
				}
				return ids;
			}
			//删除
			function del () {
				if (findIds("che").length!=0) {
					$.ajax({
						type:"get",
						url:"/sys/delDepts?dept_id="+findIds("che"),
						async:true,
						success:function (data) {
							if (data!=0) {
								alert("删除成功！！！")
								$("#t").bootstrapTable('refresh');
							} else{
								alert("删除失败！！！")
							}
						}
					});
					
				} else {
					alert("亲，请先选择你要删除的数据！！！")
				}				
			}
			
			
			function addDept(){
				
				 $.ajax({
					type: "post",
					url: "/sys/addDept",
					data:$('#fm').serialize(),
					success: function(data) {
						if (data!=0) {
							alert("添加成功！！")
							$("#myModal").modal("hide");
							location.reload()
							$("#t").bootstrapTable('refresh');
						}else{
							alert("添加失败！！")
						}
						
					} 
				});
				
			}
			
			
			//修改按钮
			function upd() {
				if (findIds("che").length==0 || findIds("che").length>1) {
					alert("亲，选择有误，请选择一条数据进行修改")
				} else{
					
					$.ajax({
						type:"post",
						url:"/sys/findDeptById?dept_id="+findIds("che"),
						async:true,
						success:function (data) {
							$("#myModal1").modal("show");
							$("#dept_id").val(data.dept_id);
							$("#pid").val(data.parent_id);
							$("#cascade_id").val(data.cascade_id);
							$("#dept_name1").val(data.dept_name);
							$("#dept_code").val(data.dept_code);
							$("#manager").val(data.manager);
							$("#phone").val(data.phone);
							$("#par1").val(data.parent_id);
							$("#is_del").val(data.is_del);
							$("#is_auto_expand").val(data.is_auto_expand);
							$("#address").val(data.address);
							$("#icon_name").val(data.icon_name);
							$("#sort_no").val(data.sort_no);
							$("#idno").val(data.idno);
							$("#fax").val(data.fax);
							$("#remark").val(data.remark);
						}
					});
				}
				
			}
			
			//修改组织
			function updDept () {
				alert(1)
				$.ajax({
					type:"post",
					url:"/sys/updDept",
					data:$("#updForm").serialize(),
					success:function (msg) {
						if (msg!=0) {
							alert("修改成功！！")
							$("#myModal1").modal("hide")
							$("#t").bootstrapTable('refresh')
						} else{
							alert("修改失败！！")
						}
					}
				});
			}
			
			
			//父节点下拉框
			$.ajax({
				type:"get",
				url:"/sys/findDeptsName",
				async:true,
				success:function (data) {
					$.each(data, function(index,data) {
						$("#par").append("<option value='"+data.dept_id+"'>"+data.dept_name+"</option>")
						$("#par1").append("<option value='"+data.dept_id+"'>"+data.dept_name+"</option>")
					});
				}
			});
			
		</script>
</head>
<body>
	
	<form class="form-inline">
		<div class="form-group">
			<label for="dept_name">机构名称：</label>
			<input type="text" class="form-control" id="dept_name" name="dept_name" placeholder="请输入机构名称">
		</div>
			<button type="button" class="btn btn-success" onclick="chaxun()"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
		<button type="reset" class="btn btn-primary"><span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>重置</button>
	</form>
	
	<table id="t">
		<div class="inline">
				<button id="add" onclick="add()" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus" style="color: green;" aria-hidden="true"></span>新增</button>
				<button id="upd" onclick="upd()" type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil" style="color: green;" aria-hidden="true"></span>修改</button>
				<button id="del" onclick="del()" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除</button>
		</div>
	</table>
	
	<!--添加的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 1000px; height: 1500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">新增组织机构</h4>
					</div>
					<div class="modal-body">
						
						<!--添加form表单-->
						<form id="fm">
							<div class="modal-body">
								<div class="form-group"><!--机构名称-->
									<label for="dept_name" class="col-sm-3 control-label">机构名称:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="dept_name" placeholder="请输入机构名称">
									</div>
									<label for="username" class="col-sm-3 control-label">上级机构:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="username" placeholder="请输入上级机构">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="cascade_id" class="col-sm-3 control-label">节点语义ID：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="cascade_id" placeholder="节点语义ID">
									</div>
									<label for="parent_id" class="col-sm-3 control-label">父节点流水号：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="parent_id" placeholder="父节点流水号">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="dept_code" class="col-sm-3 control-label">机构代码：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="dept_code" placeholder="机构代码">
									</div>
									<label for="manager" class="col-sm-3 control-label">主要负责人：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="manager" placeholder="主要负责人">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="phone" class="col-sm-3 control-label">电话：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="phone" placeholder="电话">
									</div>
									<label for="fax" class="col-sm-3 control-label">传真：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="fax" placeholder="传真">
									</div>
								</div>
							</div>
							
							
							<div class="modal-body">
								<div class="form-group">
									<label for="address" class="col-sm-3 control-label">地址：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="address" placeholder="地址">
									</div>
									<label for="icon_name" class="col-sm-3 control-label">节点图标：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="icon_name" placeholder="节点图标">
									</div>
								</div>
							</div>
							
							
			
							<div class="modal-body">
								<div class="form-group">
									<label for="remark" class="col-sm-3 control-label">备注:</label>
									<div class="col-sm-7">
										<textarea class="form-control" name="remark" rows="2"></textarea>
									</div>
								</div>
							</div>
						</form>
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<button type="button" class="btn btn-primary" onclick="addDept()">Add</button>
					</div>
				</div>
			</div>
		</div>
		
		
		<!--修改的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 1000px; height: 1500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">修改组织</h4>
					</div>
					<div class="modal-body">
						 
						<!--修改form表单-->
						<form id="updForm">
							<input type="hidden" id="dept_id" name="dept_id" />
							<input type="hidden" id="pid" name="param_id"/>
							<div class="modal-body">
								<div class="form-group">
									<label for="cascade_id" class="col-sm-3 control-label">节点语义ID:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="cascade_id" name="cascade_id" placeholder="Cascade_id">
									</div>
									<label for="dept_name" class="col-sm-3 control-label">组织名称:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="dept_name1" name="dept_name" placeholder="Dept_name">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="dept_code" class="col-sm-3 control-label">机构代码：</label><!--用户密码-->
									<div class="col-sm-3">
										<input type="text" class="form-control" id="dept_code" name="dept_code" placeholder="Dept_code">
									</div>
									<label for="manager" class="col-sm-3 control-label">主要负责人：</label><!--确认密码-->
									<div class="col-sm-3">
										<input type="text" class="form-control" id="manager" name="manager" placeholder="Manager">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="phone" class="col-sm-3 control-label">部门电话:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="phone" name="phone" placeholder="Phone">
									</div>
									<label for="parent_id" class="col-sm-3 control-label">父节点流水号：</label>
									<div class="col-sm-3">
										<select class="form-control" id="par1" name="parent_id">
											
										</select>
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="is_del" class="col-sm-3 control-label">是否已删除:</label>
									<div class="col-sm-3">
										<select class="form-control" id="is_del" name="is_del">
											<option value="0">有效</option>
											<option value="1">删除</option>
										</select>
									</div>
									<label for="is_auto_expand" class="col-sm-3 control-label">是否自动展开：</label>
									<div class="col-sm-3">
										<select class="form-control" id="is_auto_expand" name="is_auto_expand">
											<option value="0">---  ---</option>
											<option value="1">是</option>
											<option value="2">否</option>
										</select>
									</div>
								</div>
							</div>
												
							<div class="modal-body">
								<div class="form-group">
									<label for="address" class="col-sm-3 control-label">地址:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="address" name="address" placeholder="Address">
									</div>
									<label for="icon_name" class="col-sm-3 control-label">节点图标文件名称：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="icon_name" name="icon_name" placeholder="Icon_name">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="sort_no" class="col-sm-3 control-label">排序号:</label>
									<div class="col-sm-3">
										<input type="number" class="form-control" id="sort_no" name="sort_no" placeholder="Sort_no">
									</div>
									<label for="idno" class="col-sm-3 control-label">证件号：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="idno" name="idno" placeholder="Idno">
									</div>	
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
								<label for="fax" class="col-sm-3 control-label">传真：</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="fax" name="fax" placeholder="Fax">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="remark" class="col-sm-3 control-label">备注:</label>
									<div class="col-sm-7">
										<textarea class="form-control" id="remark" name="remark" rows="2"></textarea>
									</div>
								</div>
							</div>
						</form>
						
					</div>
					<div>
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<button type="button" class="btn btn-primary" onclick="updDept()">Update</button>
					</div>
				</div>
			</div>
		</div>
</body>
</html>